package com.woniuxy.happylife.datastore.controller;

import com.woniuxy.happylife.datastore.service.ActiveService;
import com.woniuxy.happylife.entity.ActivityRelease;
import com.woniuxy.happylife.entity.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 管理活动查询controller
 */
@RestController
@RequestMapping("/view")
public class ViewActiveController {

    /**
     * 活动查询service
     */
    @Resource
    ActiveService activeServiceImpl;

    /**
     * 查询物业的活动
     * @return
     */
    @RequestMapping("/viewManagementActivity")
    public ResponseEntity viewManagementActivity(){
        //查询出所有活动
        List<ActivityRelease> activityReleases = activeServiceImpl.active();
        //将活动类里发布用户角色为1的活动返回出去
        // (我这里在rpac_role里定义了物业角色,id为1),整合代码时直接改stream里的filter,不用改dao、mapperXML
        List<ActivityRelease> collect = activityReleases.stream()
                .filter(e -> e.getReleaseUser().getRoleId().equals("1"))
                .collect(Collectors.toList());
        return new ResponseEntity(200, "查询成功", collect);

    }

    /**
     * 查询商家的活动
     * @return
     */
    @RequestMapping("/viewShopActivity")
    public ResponseEntity viewShopActivity(){
        //查询出所有活动
        List<ActivityRelease> activityReleases = activeServiceImpl.active();
        //将活动类里发布用户角色为2的活动返回出去
        // (我这里在rpac_role里定义了商户角色,id为2),整合代码时直接改stream里的filter,不用改dao、mapperXML
        List<ActivityRelease> collect = activityReleases.stream()
                .filter(e -> e.getReleaseUser().getRoleId().equals("2"))
                .collect(Collectors.toList());
        return new ResponseEntity(200, "查询成功", collect);
    }
}
